package cn.edu.nju.askme.action;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.apache.struts2.interceptor.SessionAware;
import org.springframework.stereotype.Component;

import cn.edu.nju.askme.model.Paper;
import cn.edu.nju.askme.model.User;
import cn.edu.nju.askme.service.IPaperService;

import com.opensymphony.xwork2.ActionSupport;

@Component
public class PaperCreateAction extends ActionSupport implements SessionAware {

	private Paper paper;

	private Map session;
	private List<Paper> paperList;
	private IPaperService paperService;
	public Map getSession() {
		return session;
	}

	public void setSession(Map session) {
		this.session = session;
	}

	public Paper getPaper() {
		return paper;
	}

	public void setPaper(Paper paper) {
		this.paper = paper;
	}

	public List<Paper> getPaperList() {
		return paperList;
	}

	public void setPaperList(List<Paper> paperList) {
		this.paperList = paperList;
	}

	public IPaperService getPaperService() {
		return paperService;
	}

	@Resource
	public void setPaperService(IPaperService paperService) {
		this.paperService = paperService;
	}

	public String addPaperInfo() {
		System.out.println("PaperCreateAction.addPaperInfo()");
		User user = (User)session.get("user");
		paper.setUser(user);
/*		session.put("paper", paper);
*/		paperService.add(paper);
		paperList= paperService.checkByCreator(user);
		return SUCCESS;
	}

}
